home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsmemraw.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.9 KB  |  198 lines

  1. /* Copyright (C) 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsmemraw.h,v 1.2 2000/09/19 19:00:30 lpd Exp $ */
  20. /* Client interface for "raw memory" allocator */
  21.  
  22. /* Initial version 02/03/1998 by John Desrosiers (soho@crl.com) */
  23. /* Completely rewritten 6/26/1998 by L. Peter Deutsch <ghost@aladdin.com> */
  24.  
  25. #ifndef gsmemraw_INCLUDED
  26. #  define gsmemraw_INCLUDED
  27.  
  28. /*
  29.  * This interface provides minimal memory allocation and freeing capability.
  30.  * It is meant to be used for "wholesale" allocation of blocks -- typically,
  31.  * but not only, via malloc -- which are then divided up into "retail"
  32.  * objects.  However, since it is a subset (superclass) of the "retail"
  33.  * interface defined in gsmemory.h, retail allocators implement it as
  34.  * well, and in fact the malloc interface defined in gsmalloc.h is used for
  35.  * both wholesale and retail allocation.
  36.  */
  37.  
  38. /*
  39.  * Define the structure for reporting memory manager statistics.
  40.  */
  41. typedef struct gs_memory_status_s {
  42.     /*
  43.      * "Allocated" space is the total amount of space acquired from
  44.      * the parent of the memory manager.  It includes space used for
  45.      * allocated data, space available for allocation, and overhead.
  46.      */
  47.     ulong allocated;
  48.     /*
  49.      * "Used" space is the amount of space used by allocated data
  50.      * plus overhead.
  51.      */
  52.     ulong used;
  53. } gs_memory_status_t;
  54.  
  55. /* Define the abstract type for the memory manager. */
  56. typedef struct gs_raw_memory_s gs_raw_memory_t;
  57.  
  58. /* Define the procedures for raw memory management.  Memory managers have no
  59.  * standard constructor: each implementation defines its own, and is
  60.  * responsible for calling its superclass' initialization code first.
  61.  * Similarly, each implementation's destructor (release) must first take
  62.  * care of its own cleanup and then call the superclass' release.
  63.  */
  64.  
  65.         /*
  66.          * Allocate bytes.  The bytes are always aligned maximally
  67.          * if the processor requires alignment.
  68.          *
  69.          * Note that the object memory level can allocate bytes as
  70.          * either movable or immovable: raw memory blocks are
  71.          * always immovable.
  72.          */
  73.  
  74. #define gs_memory_t_proc_alloc_bytes(proc, mem_t)\
  75.   byte *proc(P3(mem_t *mem, uint nbytes, client_name_t cname))
  76.  
  77. #define gs_alloc_bytes_immovable(mem, nbytes, cname)\
  78.   ((mem)->procs.alloc_bytes_immovable(mem, nbytes, cname))
  79.  
  80.         /*
  81.          * Resize an object to a new number of elements.  At the raw
  82.          * memory level, the "element" is a byte; for object memory
  83.          * (gsmemory.h), the object may be an an array of either
  84.          * bytes or structures.  The new size may be larger than,
  85.          * the same as, or smaller than the old.  If the new size is
  86.          * the same as the old, resize_object returns the same
  87.          * object; otherwise, it preserves the first min(old_size,
  88.          * new_size) bytes of the object's contents.
  89.          */
  90.  
  91. #define gs_memory_t_proc_resize_object(proc, mem_t)\
  92.   void *proc(P4(mem_t *mem, void *obj, uint new_num_elements,\
  93.         client_name_t cname))
  94.  
  95. #define gs_resize_object(mem, obj, newn, cname)\
  96.   ((mem)->procs.resize_object(mem, obj, newn, cname))
  97.  
  98.         /*
  99.          * Free an object (at the object memory level, this includes
  100.          * everything except strings).  Note: data == 0 must be
  101.          * allowed, and must be a no-op.
  102.          */
  103.  
  104. #define gs_memory_t_proc_free_object(proc, mem_t)\
  105.   void proc(P3(mem_t *mem, void *data, client_name_t cname))
  106.  
  107. #define gs_free_object(mem, data, cname)\
  108.   ((mem)->procs.free_object(mem, data, cname))
  109.  
  110.         /*
  111.          * Report status (assigned, used).
  112.          */
  113.  
  114. #define gs_memory_t_proc_status(proc, mem_t)\
  115.   void proc(P2(mem_t *mem, gs_memory_status_t *status))
  116.  
  117. #define gs_memory_status(mem, pst)\
  118.   ((mem)->procs.status(mem, pst))
  119.  
  120.         /*
  121.          * Return the stable allocator for this allocator.  The
  122.          * stable allocator allocates from the same heap and in
  123.          * the same VM space, but is not subject to save and restore.
  124.          * (It is the client's responsibility to avoid creating
  125.          * dangling pointers.)
  126.          *
  127.          * Note that the stable allocator may be the same allocator
  128.          * as this one.
  129.          */
  130.  
  131. #define gs_memory_t_proc_stable(proc, mem_t)\
  132.   mem_t *proc(P1(mem_t *mem))
  133.  
  134. #define gs_memory_stable(mem)\
  135.   ((mem)->procs.stable(mem))
  136.  
  137.         /*
  138.          * Free one or more of: data memory acquired by the allocator
  139.          * (FREE_ALL_DATA), overhead structures other than the
  140.          * allocator itself (FREE_ALL_STRUCTURES), and the allocator
  141.          * itself (FREE_ALL_ALLOCATOR).  Note that this requires
  142.          * allocators to keep track of all the memory they have ever
  143.          * acquired, and where they acquired it.  Note that this
  144.          * operation propagates to the stable allocator (if
  145.          * different).
  146.          */
  147.  
  148. #define FREE_ALL_DATA 1
  149. #define FREE_ALL_STRUCTURES 2
  150. #define FREE_ALL_ALLOCATOR 4
  151. #define FREE_ALL_EVERYTHING\
  152.   (FREE_ALL_DATA | FREE_ALL_STRUCTURES | FREE_ALL_ALLOCATOR)
  153.  
  154. #define gs_memory_t_proc_free_all(proc, mem_t)\
  155.   void proc(P3(mem_t *mem, uint free_mask, client_name_t cname))
  156.  
  157. #define gs_memory_free_all(mem, free_mask, cname)\
  158.   ((mem)->procs.free_all(mem, free_mask, cname))
  159. /* Backward compatibility */
  160. #define gs_free_all(mem)\
  161.   gs_memory_free_all(mem, FREE_ALL_DATA, "(free_all)")
  162.  
  163.         /*
  164.          * Consolidate free space.  This may be used as part of (or
  165.          * as an alternative to) garbage collection, or before
  166.          * giving up on an attempt to allocate.
  167.          */
  168.  
  169. #define gs_memory_t_proc_consolidate_free(proc, mem_t)\
  170.   void proc(P1(mem_t *mem))
  171.  
  172. #define gs_consolidate_free(mem)\
  173.   ((mem)->procs.consolidate_free(mem))
  174.  
  175. /* Define the members of the procedure structure. */
  176. #define gs_raw_memory_procs(mem_t)\
  177.     gs_memory_t_proc_alloc_bytes((*alloc_bytes_immovable), mem_t);\
  178.     gs_memory_t_proc_resize_object((*resize_object), mem_t);\
  179.     gs_memory_t_proc_free_object((*free_object), mem_t);\
  180.     gs_memory_t_proc_stable((*stable), mem_t);\
  181.     gs_memory_t_proc_status((*status), mem_t);\
  182.     gs_memory_t_proc_free_all((*free_all), mem_t);\
  183.     gs_memory_t_proc_consolidate_free((*consolidate_free), mem_t)
  184.  
  185. /*
  186.  * Define an abstract raw-memory allocator instance.
  187.  * Subclasses may have additional state.
  188.  */
  189. typedef struct gs_raw_memory_procs_s {
  190.     gs_raw_memory_procs(gs_raw_memory_t);
  191. } gs_raw_memory_procs_t;
  192. struct gs_raw_memory_s {
  193.     gs_raw_memory_t *stable_memory;    /* cache the stable allocator */
  194.     gs_raw_memory_procs_t procs;
  195. };
  196.  
  197. #endif /* gsmemraw_INCLUDED */
  198.